
	var Path = CONFIG.ApiPath;
	var ApiVersion = CONFIG.ApiVersion;
	var _location = window.location;
	
	var getUrlParam = function(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = _location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    };
    
    var fnAjax = function(oArg) {
		return;

        //请求路径
        var Path = {
            "fs": CONFIG.fsPath,
            "zp": CONFIG.ApiPath
        }[oArg.Path || "zp"];

        var re = /[\u4e00-\u9fa5]+/,
            oData = [],
            n, v; // 处理oArg.oData中的数组

        //请求参数oData
        if (oArg.oData) {
            if (typeof oArg.oData == 'string') {
                oData = oArg.oData;
            } else {
                for (n in oArg.oData) {
                    if (oArg.oData[n] instanceof Array) {
                        for (var k in oArg.oData[n]) {
                            oData.push({
                                name: n,
                                value: oArg.oData[n][k]
                            });
                        }
                    } else {
                        v = oArg.oData[n];
                        v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
                        oData.push({
                            name: n,
                            value: v
                        });
                    }
                }
            }
        }
        
        oData.push({
            name: "sessionUuid",
            value: window.localStorage.getItem("sid")
        }); //sessionUuid
        oData.push({
            name: "appKey",
            value: window.localStorage.getItem("appKey")
        }); //appKey
        
        //版本号
        //参数组合
        var opts = {
            url: Path + ApiVersion + "/" + oArg.action+"",
            type: oArg.stype || "POST",
            async: oArg.async == false ? false : true, //默认异步
            dataType: oArg.dataType || 'json',
            data: oData,
            success: function(oRes) {
                oArg.fnSuccess && oArg.fnSuccess(oRes);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                T.alert(3, "服务器异常,请稍后再试", 2000);
                oArg.error && oArg.error();
            }
        };

        $.ajax(opts);
    };
    
    var fileUuid = getUrlParam("fileUuid");

	clearValue = function(obj) {
		$(obj).val("");
	}
	
	getCanvasDate = function(obj){
   	    var data1 = this.canvas.toDataURL("image/jpeg");
		if($("#sign_cont_03").css("display")=="block"){
			if (data1 =="") { 					
				showAlert("画布为空，请先手绘签名再提交！");
			}else{
				$("#sealway").val(3);
				$("#Template").val("")
				var postData = "sealWay=" + 3 + "&color=" + 1 +"&base64=" + data1 + "&edit=" + (new Date()).valueOf();
				showblockUI();
				$.ajax({
					url : "../user/seal!compressSeal.xml",
					type : "get",
					data : postData,
					dataType : "xml",
					timeout : 300000,
					error : function() {
						closeAlert();
					},
					success : function(data) {
						closeAlert();
						var result = $(data).find("result >resultMsg").text();
						if (result == null || result == "") {
							showAlert("系统出错，请稍后重试");
							return;
						}
						var jsonData = JSON.parse(result);
						var errCode = jsonData["errCode"];
						if (errCode > 0) {
							var errShow = new Boolean(jsonData["errShow"]);
							if (errShow == true) {
								if ($(".signFlag").length <= 0 ) { 
									return;
								} 
								showAlert(jsonData["msg"]);
								showSignFont($(".nav_li_001 li").eq(2),3);
							} else {
								showAlert("系统出错，请稍后重试");
							}
							return;
						} else {
							$("#cordova").attr('src', jsonData["img1Url"]);
							$("#cordova").attr('key', jsonData["img1"]);
							$("#onlineSeal").attr("key",jsonData["img1"]);
							$("#cordova").attr('X', 95);
							$("#cordova").attr('Y', 95);
							defaultSignAjax(obj);
						}
					}
				});
			}
		}else{
			defaultSignAjax(obj);
		}
	}
	
	modelSeal = function(obj) {
		if (obj == '') {
			$("#fonttype li").each(function(index){
				if($(this).hasClass("selected")) {
					obj = this;
				}
			});
		}
		$("#fonttype li").removeClass("selected");
		$(obj).addClass("selected");
		var typeName = $("#typeName").val();
		if(typeName == "可在此处输入横向文") {
			typeName = "";
		}
		var rune = $("#rune").val();
		if(rune == "可在此处输入下弦文") {
			rune = "";
		}
		$("#Template").val($(obj).attr("value"));
		$("#sealway").val(1);
		
		var seal = sealCompare.compare($(obj).attr("value"));
		if(seal){
			//若存在，存放sealid
			$("#onlineSeal").attr("sealId",seal["id"]);
			$("#model").attr('src', seal["imgUrl"]);
			$("#model").attr('key', "");
			if($("#fonttype2").hasClass("selected")) {
				if($("#type").val()=="2") {
					$("#model").attr('X', 170);
					$("#model").attr('Y', 113);
					$("#model").attr('style', 'width:226px;height:140px;margin-top: 30px');
					$("#picSize").attr('style', 'width:210px;height:182px');
				}
			} else {
				if($("#type").val()=="2") {
					$("#model").attr('X', 159);
					$("#model").attr('Y', 159);
					$("#model").attr('style', 'width:170px;height:170px;');
					$("#picSize").attr('style', 'width:210px;');
				} else {
					$("#model").attr('X', 95);
					$("#model").attr('Y', 95);
					$("#model").attr('style', 'width:170px;height: 170px');
					$("#picSize").attr('style', 'width:210px');
				}
			}
			return ;
		}
		
		
		$("#onlineSeal").attr("sealId","");
		var postData = "sealWay=" + 1 + "&templateName=" + $(obj).attr("value") + "&color=" + 1 + "&typeName=" + typeName + "&rune=" + rune + "&edit=" + (new Date()).valueOf();
		showblockUI();
		$.ajax({
			url : "../user/seal!compressSeal.xml",
			type : "get",
			data : postData,
			async:true,
			dataType : "xml",
			timeout : 300000,
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				//console.log(errorThrown);
				closeAlert();
			},
			success : function(data) {
				closeAlert();
				var result = $(data).find("result >resultMsg").text();
				if (result == null || result == "") {
					showAlert("系统出错，请稍后重试");
					return;
				}
				var jsonData = JSON.parse(result);
				var errCode = jsonData["errCode"];
				if (errCode > 0) {
					var errShow = new Boolean(jsonData["errShow"]);
					if (errShow == true) {
						if ($(".signFlag").length <= 0 ) { 
							return;
						} 
						var type = $("#type").val();
						if(errCode ==2031){
							modelSeal($("#fonttype2"));
							return ;
						}
						if (type == 1) {
							showAlert(jsonData["msg"]);
							showSignFont($(".nav_li_001 li").eq(4),5);
						} else {
							showUrlMust("您的基本信息不全，前往补全基本信息", "organize!page?skip=info");
						}
					} else {
						showAlert("系统出错，请稍后重试");
					}
					return;
				} else {
					$("#onlineSeal").attr("templateName",$(obj).attr("value"));
					$("#onlineSeal").attr("typeName",typeName);
					$("#onlineSeal").attr("rune",rune);
					$("#onlineSeal").attr("sealWay",1);
					$("#onlineSeal").attr("key",jsonData["img1"]);
					$("#model").attr('src', jsonData["img1Url"]);
					$("#model").attr('key', jsonData["img1"]);
					
					if($("#fonttype2").hasClass("selected") && $("#type").val()=="2") {
						$("#model").attr('X', 170);
						$("#model").attr('Y', 113);
						$("#model").attr('style', 'width:226px;height:140px;margin-top: 30px');
						$("#picSize").attr('style', 'width:210px;height:182px');
					} else {
						if($("#type").val()=="2") {
							$("#model").attr('X', 159);
							$("#model").attr('Y', 159);
							$("#model").attr('style', 'width:170px;height:170px;');
							$("#picSize").attr('style', 'width:210px;');
						} else {
							$("#model").attr('X', 95);
							$("#model").attr('Y', 95);
							$("#model").attr('style', 'width:170px;height: 170px');
							$("#picSize").attr('style', 'width:210px');
						}
					}
				}
			}
		});
	}
	
	selectSeal = function(obj) {
		$("#onlineSeal").attr("sealType",$(obj).attr("sealType"));
		$("#onlineSeal").attr("sealId",$(obj).attr("sealId"));
		$("#firstSeal").css('border-color', "#d2dacc");
		$("#secondSeal").css('border-color', "#d2dacc");
		$("#thirdSeal").css('border-color', "#d2dacc");
		$(obj).css('border-color', "red");
		$("#imgurl").html("");
		$("#imgurl").append("<a href='javascript:getCanvasDate(" + $(obj).attr("id") + ");' class='btn_use_sign fl' >采用并签名</a>");
	}
	getBeforeThree = function(type) {
		$(".history-box>img").hide();
		if(type == undefined){
			type="";
		}
		$("#after"+type).attr('style', 'background-color:#e74031');
		$("#after"+type).attr('href', "javascript:getAfterThree('"+type+"');");
		var startIndex = parseInt($("#startIndex"+type).val()) - 3;
		$("#startIndex"+type).val(startIndex);
		if (startIndex == 0) {
			$("#before"+type).attr('style', 'background-color: #e0e0e0');
			$("#before"+type).removeAttr('href')
		}
		//$("#firstSeal"+type).attr('style', 'width:140px;height:140px');
		//$("#secondSeal"+type).attr('style', 'width:140px;height:140px');
		//$("#thirdSeal"+type).attr('style', 'width:140px;height:140px');
		if(type == ""){
			type=undefined;
		}
		getThreeSeal(type);
	}
	getAfterThree = function(type) {
		$(".history-box>img").hide();
		if(type == undefined){
			type="";
		}
		$("#before"+type).attr('style', 'background-color:#e74031');
		$("#before"+type).attr('href', "javascript:getBeforeThree('"+type+"');");
		var startIndex = parseInt($("#startIndex"+type).val()) + 3;
		$("#startIndex"+type).val(startIndex);
		//$("#firstSeal"+type).attr('style', 'width:140px;height:140px');
		//$("#secondSeal"+type).attr('style', 'width:140px;height:140px');
		//$("#thirdSeal"+type).attr('style', 'width:140px;height:140px');
		if(type == ""){
			type=undefined;
		}
		getThreeSeal(type);
	}
	getThreeSeal = function(type) {
		var startNum = "";
		var postData = "";
		var url = "";
		var name = "";
		if(type == undefined){
			 type="";
			 startNum = $("#startIndex").val();
			 postData = "startNum=" + startNum + "&num=" + 4 + "&hasAudit=1&edit=" + (new Date()).valueOf();
//			 url = "seal!getSeals.xml";//此处为获取印章
			 url = Path + ApiVersion + "/" + "sealGetSeals.json",
			 name = "历史";
		}
		if(type == 'grant'){
			 startNum = $("#startIndex"+type).val();
			 postData = "startNum=" + startNum + "&num=" + 4 + "&hasAudit=1&edit=" + (new Date()).valueOf();
			 url = "seal!getGrantSeal.xml";
			 name = "授权";
		}
	//	showblockUI();
		$.ajax({
			url :url, 
			type : "post",
			data : {
				sessionUuid: window.localStorage.getItem("sid"),
				appKey: window.localStorage.getItem("appKey")
			},
			timeout : 300000,
			error : function() {
				closeAlert();
			},
			success : function(data) {
				closeAlert();
//				var result = $(data).find("result >resultMsg").text();
				var result = JSON.stringify(data.datas[0]);
				if (result == null || result == "") {
					showAlert("系统出错，请稍后重试");
					return;
				}
				var jsonData = JSON.parse(result);
				var errCode = jsonData["errCode"];
				if (errCode > 0) {
					if ($(".signFlag").length <= 0 ) { 
						return;
					} 
					var presontype = $("#type").val();
					if (presontype == 1) {
						showEventMust("您没有"+name+"签名，自动为您切换成艺术签名", 'showSignFont($(".nav_li_001 li").eq(3),4)');
					} else {
						showEventMust("您没有"+name+"印章，自动为您切换成模板印章", 'showSignFont($(".nav_li_001 li").eq(2),4)');
					}
				} else {
					var sealInfo = "";
					var urls = jsonData["msg"];
					if (urls.length > 0) {
						sealInfo = urls[0];
						$("#firstSeal"+type).attr('src', sealInfo["imgUrl"]);
						$("#firstSeal"+type).attr('sealId', sealInfo["id"]);
						$("#firstSeal"+type).attr('sealType', sealInfo["sealType"]);
						$("#firstSeal"+type).attr('X', sealInfo["width"]);
						$("#firstSeal"+type).attr('Y', sealInfo["height"]);
						var width = parseInt(sealInfo["width"]) > parseInt(sealInfo["height"]) ? 140 : 140 / sealInfo["height"] * sealInfo["width"];
						var height = parseInt(sealInfo["height"]) > parseInt(sealInfo["width"]) ? 140 : 140 / sealInfo["width"] * sealInfo["height"];
						$("#firstSeal"+type).attr("style", "margin-top:-" + ((height/2)-20) + "px;margin-left:-" + ((width/2)-20)+"px");
						$("#firstSeal"+type).bind("load",function(){
							$("#firstSeal"+type).show();
						})

					} else {
						$("#startIndex"+type).val(startIndex);
						if (startIndex == 3) {
							$("#before"+type).attr('style', 'background-color: #e0e0e0');
							$("#before"+type).removeAttr('href')
						}
						$("#after"+type).attr('style', 'background-color: #e0e0e0');
						$("#after"+type).removeAttr('href')
						return;
					}
					if (urls.length > 1) {
						sealInfo = urls[1];
						$("#secondSeal"+type).attr('src', sealInfo["imgUrl"]);
						$("#secondSeal"+type).attr('sealId', sealInfo["id"]);
						$("#secondSeal"+type).attr('sealType', sealInfo["sealType"]);
						$("#secondSeal"+type).attr('X', sealInfo["width"]);
						$("#secondSeal"+type).attr('Y', sealInfo["height"]);
						var width = parseInt(sealInfo["width"]) > parseInt(sealInfo["height"]) ? 140 : 140 / sealInfo["height"] * sealInfo["width"];
						var height = parseInt(sealInfo["height"]) > parseInt(sealInfo["width"]) ? 140 : 140 / sealInfo["width"] * sealInfo["height"];
						$("#secondSeal"+type).attr("style", "margin-top:-" + ((height/2)-20) + "px;margin-left:-" + ((width/2)-20)+"px");
						$("#secondSeal"+type).bind("load",function(){
							$("#secondSeal"+type).show();
						})
					} else {
						$("#secondSeal"+type).attr('src', '');
						$("#secondSeal"+type).attr('sealId', '');
						$("#secondSeal"+type).hide();
					}
					if (urls.length > 2) {
						sealInfo = urls[2];
						$("#thirdSeal"+type).attr('src', sealInfo["imgUrl"]);
						$("#thirdSeal"+type).attr('sealId', sealInfo["id"]);
						$("#thirdSeal"+type).attr('sealType', sealInfo["sealType"]);
						$("#thirdSeal"+type).attr('X', sealInfo["width"]);
						$("#thirdSeal"+type).attr('Y', sealInfo["height"]);
						var width = parseInt(sealInfo["width"]) > parseInt(sealInfo["height"]) ? 140 : 140 / sealInfo["height"] * sealInfo["width"];
						var height = parseInt(sealInfo["height"]) > parseInt(sealInfo["width"]) ? 140 : 140 / sealInfo["width"] * sealInfo["height"];
						$("#thirdSeal"+type).attr("style", "margin-top:-" + ((height/2)-20) + "px;margin-left:-" + ((width/2)-20)+"px");
						$("#thirdSeal"+type).bind("load",function(){
							$("#thirdSeal"+type).show();
						})
					} else {
						$("#thirdSeal"+type).attr('src', '');
						$("#thirdSeal"+type).attr('sealId', '');
						$("#thirdSeal"+type).hide();
					}
					if (urls.length > 3) {
						sealInfo = urls[3];
						$("#fouthSeal"+type).attr('src', sealInfo["imgUrl"]);
						$("#fouthSeal"+type).attr('sealId', sealInfo["id"]);
						$("#fouthSeal"+type).attr('sealType', sealInfo["sealType"]);
						$("#fouthSeal"+type).attr('X', sealInfo["width"]);
						$("#fouthSeal"+type).attr('Y', sealInfo["height"]);
						var width = parseInt(sealInfo["width"]) > parseInt(sealInfo["height"]) ? 140 : 140 / sealInfo["height"] * sealInfo["width"];
						var height = parseInt(sealInfo["height"]) > parseInt(sealInfo["width"]) ? 140 : 140 / sealInfo["width"] * sealInfo["height"];
						$("#fouthSeal"+type).attr("style", "margin-top:-" + ((height/2)-20) + "px;margin-left:-" + ((width/2)-20)+"px");
						$("#fouthSeal"+type).bind("load",function(){
							$("#fouthSeal"+type).show();
						})
					} else {
						$("#fouthSeal"+type).attr('src', '');
						$("#fouthSeal"+type).attr('sealId', '');
						$("#fouthSeal"+type).hide();
					}
					if (urls.length > 4) {
						
					} else {
						$("#after"+type).attr('style', 'background-color: #e0e0e0');
						$("#after"+type).removeAttr('href')
					}
				}
			}
		});
	};
	
	getDefaultSeal = function() {
	//	showblockUI();
		var postData = "defaultSeal=1&edit=" + (new Date()).valueOf();
		$.ajax({
			url : "seal!getSeals.xml",//此处为获取印章
			type : "get",
			data : postData,
			dataType : "xml",
			timeout : 300000,
			error : function() {
				closeAlert();
			},
			success : function(data) {
				closeAlert();
				var result = $(data).find("result >resultMsg").text();
				if (result == null || result == "") {
					showAlert("系统出错，请稍后重试");
					return;
				}
				var jsonData = JSON.parse(result);
				var errCode = jsonData["errCode"];
				if (errCode > 0) {
					if ($(".signFlag").length <= 0 ) { 
						return;
					} 
					if(errCode == 1){
						var type = $("#type").val();
						if (type == 1) {
							showEventMust("您没有任何印章，自动为您切换成艺术签名", 'showSignFont($(".nav_li_001 li").eq(3),4)');
						} else {
							showEventMust("您没有任何印章，自动为您切换成模板印章", 'showSignFont($(".nav_li_001 li").eq(2),4)');
						}
					}

				} else {
						
					if(jsonData["msg"].length == 0){
						var type = $("#type").val();
						if (type == 1) {
							showEventMust("您没有默认签名，自动为您切换成艺术签名", 'showSignFont($(".nav_li_001 li").eq(3),4)');
						} else {
							showEventMust("您没有默认印章，自动为您切换成模板印章", 'showSignFont($(".nav_li_001 li").eq(2),4)');
						}
						return ;
					}
					Defaultseal = jsonData["msg"][0];
					$("#defaultSeal").attr('src', Defaultseal["imgUrl"]);
					$("#defaultSeal").attr('sealId', Defaultseal["id"]);
					$("#defaultSeal").attr('X', Defaultseal["width"]);
					$("#defaultSeal").attr('Y', Defaultseal["height"]);
					//if (Defaultseal["width"] > Defaultseal["height"]) {
					//	$("#defaultSeal").attr("style", "width:226px;height:140px;margin-left: -3px;margin-top: 40px");
					//} else if (Defaultseal["height"] > Defaultseal["width"]) {
					//	$("#defaultSeal").attr("style", "width:105px;height:170px;margin-left: 60px");
					//} else {
					//	$("#defaultSeal").attr("style", "width:170px;height:170px;");
					//}
					var width = parseInt(Defaultseal["width"]) > parseInt(Defaultseal["height"]) ? 170 : 170 / Defaultseal["height"] * Defaultseal["width"];
					var height = parseInt(Defaultseal["height"]) > parseInt(Defaultseal["width"]) ? 170 : 170 / Defaultseal["width"] * Defaultseal["height"];
					$("#defaultSeal").css("margin-top", "-" + (height/2)+"px");
					$("#defaultSeal").css("margin-left","-" + (width/2)+"px")
				}
			}
		});
	};
	
	getImgInfo = function(src) {
		pic.src = src;
	}
	
	reloadSize = function(obj) {
		var width = obj["width"];
		var height = obj["height"];
		if (width == height) {
			var fileWidth = pic.width;
			var fileHeight = pic.height;
			if (fileWidth > fileHeight) {
				obj["height"] = height * (fileHeight / fileWidth);
            } else {
            	obj["width"] = width * (fileWidth / fileHeight);
            }
		}
		
	}
	
	
	getFiveImgUrl = function(signdocId, signdocName, pageList) {
		var screenWidth = screen.width;
		var pageNum = pageList[0] + "-" + pageList[1];
		var postData = "pageNum=" + pageNum + "&signdocId=" + signdocId;
		if ($("#accountUid").length > 0) {
			var accountUid = $("#accountUid").val();
			if($("#accountUid").val() != "") {
				postData += "&accountUid=" + accountUid;		
			}
		}
		postData += "&edit=" + (new Date()).valueOf();

//		//此处为关键点 by zxh
//		/**
//		  *
//		  * <result>
//				<resultMsg>
//					{"docName":"测试.pdf","cloudCount":0,"keys":[{"imageKey":"https://esign-oss-release.oss-cn-hangzhou.aliyuncs.com/docimagetmp/doc_zjjr56%40qq.com_6855614_1?Expires=1497342097&OSSAccessKeyId=FBzUaPMorqiiUAfb&Signature=VHLLcq0r%2BpxuYG764skvOxGOhMA%3D","page":1,"ossKey":"docimagetmp/doc_zjjr56@qq.com_6855614_1"}],"errCode":0,"waitForTaCount":0,"iSendbackCount":0,"msg":"","downUrl":null,"pageHeight":841.92,"draftCount":0,"pageNum":11,"sendbackCount":0,"waitForMeCount":0,"pageWidth":595.32,"doneCount":0,"errShow":false,"docId":0,"closeCount":0,"otherSendbackCount":0}
//				</resultMsg>
//			</result>
//		  */
		
		$.ajax({
//			url : "sign!getDocPic.xml",
			url : Path + ApiVersion + "/" + "getDocPic.json",
			type : "POST",
			async: false,
			data : {
				fileUuid: fileUuid
			},
			timeout : 300000,
			error : function() {
			},
			success:function(data){
				closeAlert();
//				var result = $(data).find("result >resultMsg").text();
				var result =  JSON.stringify(data.datas[0]);
				if (result == null || result == "") {
					showAlert("系统出错，请稍后重试");
					return;
				}
				var jsonData = JSON.parse(result);
				var errCode = jsonData["errCode"];
				if (errCode > 0) {
					var errShow = new Boolean(jsonData["errShow"]);
					if (errShow == true) {
						showAlert(jsonData["msg"]);
					} else {
						showAlert("系统出错，请稍后重试");
					}
					return;
				} else {
					if(jsonData["pageNum"] == 0){
						showAlert("pdf文件解析异常！");
					}
					$("#currentPageNum").val(jsonData["pageNum"]);
					$("#start-staple").attr("max",jsonData["pageNum"]);
					$("#end-staple").val(jsonData["pageNum"]);
					$("#end-staple").attr("default-data",jsonData["pageNum"]);
					$("#end-staple").attr("max",jsonData["pageNum"]);
					var scale = jsonData["pageHeight"]/jsonData["pageWidth"];
					var keyArray = jsonData["keys"];
					var key;
					var finishPage = parseInt(pageList[1]);
					for (var i = 0; i < keyArray.length; i = i + 1) {
						key = keyArray[i];
						console.log(key["page"]);
						var firstId = "page_" + signdocName + "_" + key["page"];
						//此处为关键点【imageKey】为pdf转化为图片的服务
						$("#" + firstId).attr('style', "height: " + screenWidth*scale*0.56 + "px; width: "+ screenWidth*0.56 +"px; background:url(" + key["imageKey"] + ")  no-repeat scroll 0 0 / 100% 100% rgba(0, 0, 0, 0);");
						var secondId = signdocName + "_img_" + key["page"];
						$("#" + secondId).attr('src', key["imageKey"]);
						if (finishPage > 1 && jsonData["pageNum"] == key["page"]) {
							$(".fileScroll").css("height",$(".fileScroll").height()-47*2-2+48);
						}
						if (finishPage == key["page"]) {
							getLostImg(signdocId, signdocName, pageList)
						}
					}
					if (finishPage == 1) {
						$("#docName").text(jsonData["docName"]);
						$("#pageNum").text(jsonData["pageNum"]);
						$("#pdfWidth").val(jsonData["pageWidth"]);
						$("#pdfHeight").val(jsonData["pageHeight"]);
						setClass(signdocId + '_1');
						document.getElementById('centerPage_' + signdocId +'_1').scrollIntoView();
					}
					if (jsonData["pageHeight"] < jsonData["pageWidth"]) {
						$("#centerWar").scroll();
					}
				}
				start();
			}
		});
	}
	
	
//	getAllImgUrl = function(signdocId, signdocName, pageCount) {
//		var pageNum = 0;
//		var screenWidth = screen.width;
//		for (var i = 0; i < pageCount; i = i + 5) {
//			if (pageCount < 5) {
//				pageNum = "1-" + pageCount;
//			} else if(i <= pageCount - 5) {				
//				pageNum = (i + 1) + "-" + (i + 5);
//			} else {
//				pageNum = (i + 1) + "-" + pageCount;
//			}
//			var postData = "pageNum=" + pageNum + "&signdocId=" + signdocId;
//			if ($("#email").length > 0) {
//				var email = $("#email").val();
//				if($("#email").val() != "") {
//					postData += "&email=" + email;		
//				}
//			}
//			postData += "&edit=" + (new Date()).valueOf();
//			showblockUI();
//			$.ajax({
//				url : "sign!getDocPic.xml",
//				type : "get",
//				data : postData,
//				dataType : "xml",
//				timeout : 300000,
//				error : function() {
//				},
//				success:function(data){
//					closeAlert();
//					var result = $(data).find("result >resultMsg").text();
//					if (result == null || result == "") {
//						showAlert("系统出错，请稍后重试");
//						return;
//					}
//					var jsonData = JSON.parse(result);
//					var errCode = jsonData["errCode"];
//					if (errCode > 0) {
//						var errShow = new Boolean(jsonData["errShow"]);
//						if (errShow == true) {
//							showAlert(jsonData["msg"]);
//						} else {
//							showAlert("系统出错，请稍后重试");
//						}
//						return;
//					} else {
//						var scale = jsonData["pageHeight"]/jsonData["pageWidth"];
//						var keyArray = jsonData["keys"];
//						var key;
//						for (var i = 0; i < keyArray.length; i = i + 1) {
//							key = keyArray[i];
//							var firstId = "page_" + signdocName + "_" + key["page"];
//							$("#" + firstId).attr('style', "height: " + screenWidth*scale*0.56 + "px; width: "+ screenWidth*0.56 +"px; background:url(" + key["imageKey"] + ")  no-repeat scroll 0 0 / 100% 100% rgba(0, 0, 0, 0);");
//							var secondId = signdocName + "_img_" + key["page"];
//							$("#" + secondId).attr('src', key["imageKey"]);
//							if (pageCount > 1 && pageCount == key["page"]) {
//								$(".fileScroll").css("height",$(".fileScroll").height()-47*2-2+48);
//								setTimeout("getLostImg(" + signdocId + ", " + signdocName + ", " + jsonData["pageNum"] + ")", 1000);
//							}
//						}
//						if (pageCount == 1) {
//							$("#docName").text(jsonData["docName"]);
//							$("#pageNum").text(jsonData["pageNum"]);
//							$("#pdfWidth").val(jsonData["pageWidth"]);
//							$("#pdfHeight").val(jsonData["pageHeight"]);
//						}
//						if (pageCount == 1 && jsonData["pageNum"] > 1) {
//							createPage(jsonData["pageNum"]);
//						}
//					}
//				}
//			});
//		}
//	};
	getSeals = function() {
		alert(123);
		var postData = "isDefault=" + 0 + "&edit=" + (new Date()).valueOf();
		$.ajax({
			url : "../seal!getSeals.xml", //此处为获取印章
			type : "post",
			data : postData,
			dataType : "xml",
			timeout : 300000,
			success : function(data) {
				var result = $(data).find("result >resultMsg").text();
				if (result == null || result == "") {
					return;
				}
				var jsonData = JSON.parse(result);
				var errCode = jsonData["errCode"];
				if (errCode > 0) {
				} else {
					var items = jsonData["msg"];
					var count = 0;
					$(items).each(function(index){
						if(items[index]["status"]==1){
						count++;
						}
					});
					var onlineCount =parseInt($("#sealCount").val());
					if (onlineCount+count>=40) {
						$(".nav_li_001 li").eq(0).css("width","260px");
						$(".nav_li_001 li").eq(1).css("width","260px");
						$(".nav_li_001 li").eq(2).hide();
						$(".nav_li_001 li").eq(3).hide();
					}
				}
			}
		});
	}
	

	defaultSignAjax = function(obj){
		var sealJson = {};
		var oneSeal = {};
		var data = "";
		var id = $(obj).attr("id");
		data = $(obj).attr('src');
		var one = $("#onlineSeal").attr("objId");
		if($("#onlineChange").val()){
			$("#"+$("#onlineChange").val()).attr("src",$(obj).attr("src"));
			$("#"+$("#onlineChange").val()).css("width",$(obj).attr("x"));
			$("#"+$("#onlineChange").val()).css("height",$(obj).attr("y"));
			$("#onlineChange").val("")
		}else{
			$("#"+one).attr("src",$(obj).attr("src"));
			
		}
		sealJson["objId"]=$("#onlineSeal").attr("objId");
		sealJson["sealId"]=	$("#onlineSeal").attr("sealId");
		if($(obj).attr("id") == "defaultSeal"){
		sealJson["sealId"]=	$(obj).attr("sealId");
		}
		if(sealJson["sealId"]=="" || sealJson["sealId"]==null){
			$("#sealCount").val(parseInt($("#sealCount").val())+1);
		}						
		sealJson["templateName"]=$("#onlineSeal").attr("templateName");
		sealJson["imgUrl"] =$("#onlineSeal").attr("key");
		if($(obj).attr("id") =="cordova"){
			sealJson["imgUrl"] = $(obj).attr("key");
			sealJson["sealWay"]=3;
		}
		else if($(obj).attr("id") =="model"){
			sealJson["sealWay"]=1;
		}else{
			sealJson["sealWay"]="";
		}
		sealJson["rune"]=$("#onlineSeal").attr("rune");
		sealJson["typeName"]=$("#onlineSeal").attr("typeName");
		var type= 0;
		if ($("#type").val() == 1) {
				type = 3;
			} else {
				if($("#fonttype2").hasClass("selected")) {
					type = 15;
				} else {
    				type = 9;
				}
			}
		sealJson["type"]=type;
		sealArray[$("#onlineSeal").attr("objId")] = sealJson;
//			$(".signFlag").attr("src",data);
//			$("#signImgSrc").val(data);
		$("#"+$("#onlineSeal").attr("objId")).css('height',divPageHeight*(73/842.04)+'px');
		$("#"+$("#onlineSeal").attr("objId")).css('width',divPageWidth*(126/594.96)+'px');
		$("#sealType").attr('sealId', $(obj).attr("sealId"));
		$("#sealType").attr('key', $(obj).attr("key"));
		var adaptWidth = $(obj).attr("X");
		var adaptHeight = $(obj).attr("Y");
		
		var screenWidth = screen.width;
		var adapt = screenWidth/1440;
		adaptWidth = adaptWidth*adapt;
			adaptHeight = adaptHeight*adapt;
			$("#"+$("#onlineSeal").attr("objId")).css('width',adaptWidth);
		$("#"+$("#onlineSeal").attr("objId")).css('height',adaptHeight);
		conPosition("content_sign");
		$("#background,#content_sign").hide();
		
		$("#sealType").val(id);
		$("#"+$("#onlineSeal").attr("objId")).attr("objwidth",$(obj).attr("X"));
		$("#"+$("#onlineSeal").attr("objId")).attr("objheight",$(obj).attr("Y"));
		$("#width").val($(obj).attr("X"));
		$("#height").val($(obj).attr("Y"));
	}
	
	getLostImg = function(signdocId, signdocName, pageList) {
		var exist = 0;
		var screenWidth = screen.width;
		var pageNum = 0;
		var startPage = parseInt(pageList[0]);
		var finishPage = parseInt(pageList[1]);
		for (var i = startPage; i <= finishPage; i = i + 1) {
			pageNum = i;
			var page = $("#" + signdocId + "_img_" + pageNum);
			if (page.attr("src") == "") {
				var postData = "pageNum=" + pageNum + "&signdocId=" + signdocId;
				if ($("#email").length > 0) {
					var email = $("#email").val();
					if($("#email").val() != "") {
						postData += "&email=" + email;		
					}
				}
				postData += "&edit=" + (new Date()).valueOf();
				$.ajax({
					url : "sign!getDocPic.xml",
					type : "get",
					data : postData,
					dataType : "xml",
					timeout : 300000,
					async:false,
					error : function() {
					},
					success:function(data){
						var result = $(data).find("result >resultMsg").text();
						if (result == null || result == "") {
							showAlert("系统出错，请稍后重试");
							return;
						}
						var jsonData = JSON.parse(result);
						var errCode = jsonData["errCode"];
						if (errCode > 0) {
							var errShow = new Boolean(jsonData["errShow"]);
							if (errShow == true) {
								showAlert(jsonData["msg"]);
							} else {
								showAlert("系统出错，请稍后重试");
							}
							return;
						} else {
							if(jsonData.pageNum == 0){
								showAlert("pdf文件解析异常！");
							}
							var scale = jsonData["pageHeight"]/jsonData["pageWidth"];
							var keyArray = jsonData["keys"];
							var key;
							for (var i = 0; i < keyArray.length; i = i + 1) {
								key = keyArray[i];
								var firstId = "page_" + signdocName + "_" + key["page"];
								$("#" + firstId).attr('style', "height: " + screenWidth*scale*0.56 + "px; width: "+ screenWidth*0.56 +"px; background:url(" + key["imageKey"] + ")  no-repeat scroll 0 0 / 100% 100% rgba(0, 0, 0, 0);");
								var secondId = signdocName + "_img_" + key["page"];
								$("#" + secondId).attr('src', key["imageKey"]);
							}
						}
					}
				});
			} else {
				exist += 1;
			}
		}
		if (exist != (finishPage - startPage + 1)) {
			getLostImg(signdocId, signdocName, pageList);
		}
	}
	
//	var CODE = "";
//	var TIMER = "";
//	var TIMEOUT = 150;
//	createCode = function(HOST){
//	var postData ="edit=" + (new Date()).valueOf();
//			$.ajax({
//			url : "seal!createSealKey.xml",
//			type : "get",
//			data : postData,
//			dataType : "xml",
//			timeout : 300000,
//			success : function(data) {
//				var result = $(data).find("result >resultMsg").text();
//				if (result == null || result == "") {
//					return;
//				}
//				
//				$("#qrcodeCanvas").html("");
//				CODE = result;
//				
//				jQuery('#qrcodeCanvas').qrcode({
//						
//				text	: HOST+CODE
//			});
//			}
//		});
//	}
	
//	timeOutCode =function(){
//		showAlert("由于长时间未签名，二维码已过期，请重新生成二维码或切换其他签名方式");
//		$("#qrcodeCanvas").html("");
//		jQuery('#qrcodeCanvas').qrcode({
//		text: HOST+"timeout"
//		});
//		clearInterval(TIMER);
//}
	
//		startListener = function(Host){
//				if(TIMER != "" || TIMER != undefined){
//						clearInterval(TIMER);
//					}
//					TIMEOUT =150;
//				setTimer = function(){
//					if(TIMEOUT-- < 0){
//							timeOutCode(Host);
//							return;
//						};
//					var postData = "code="+CODE+"&edit="+(new Date()).toString();
//					$.ajax({
//					url : "seal!getMobileSeal.xml",
//					type : "get",
//					data : postData,
//					dataType : "xml",
//					timeout : 300000,
//					success : function(data) {
//						var result = $(data).find("result >resultMsg").text();
//						if (result == null || result == ""){
//							return;
//						}
//					var jsonData = JSON.parse(result);
//					var errCode = jsonData["errCode"];
//					if (errCode > 0) {
//						var errShow = new Boolean(jsonData["errShow"]);
//						if (errShow == true) {
//							if ($(".signFlag").length <= 0 ) { 
//								return;
//							} 
//							showAlert(jsonData["msg"]);
//
//						} else {
//							showAlert("系统出错，请稍后重试");
//						}
//						return;
//					}else{
//						clearInterval(TIMER);
//						TIMER = "";
//						$("#cordova").attr('src', jsonData["img1Url"]);
//						$("#cordova").attr('key', jsonData["img1"]);
//						$("#onlineSeal").attr("key",jsonData["img1"]);
//						$("#cordova").attr('X', 95);
//						$("#cordova").attr('Y', 95);
//						defaultSignAjax('#cordova');
//						}
//					}
//				});
//				}
//					TIMER = setInterval(setTimer, 2000);
//				}
		
		//获取历史印章
//		getGrantSeal = function(){
//			 var postData = "startNum=" + 0 + "&num=" + 4 + "&hasAudit=1&edit=" + (new Date()).valueOf();
//			$.ajax({
//				url :"seal!getGrantSeal.xml",
//				type : "get",
//				data : postData,
//				dataType : "xml",
//				timeout : 300000,
//				error : function() {
//					closeAlert();
//				},
//				success:function(data){
//				closeAlert();
//				var result = $(data).find("result >resultMsg").text();
//				if (result == null || result == "") {
//					showAlert("系统出错，请稍后重试");
//					return;
//				}
//				var jsonData = JSON.parse(result);
//				var errCode = jsonData["errCode"];
//				if(errCode >0){
//					$("ul.nav_li_001 li").eq(2).hide();
//					
//					if($("#type").val() == 2){
//						$("ul.nav_li_001 li").css("width","170px");
//					}
//					if($("#type").val() == 1){
//						$("ul.nav_li_001 li").css("width","130px");
//					}
//					}
//				}
//			})
//		}

